from google.appengine.api import users

class GoogleAccountMiddleware(object):
    """
    This is a very simple middleware that add google account user to request
    """
    def process_request(self, request):
        user = {}
        
        user['user'] = users.get_current_user()
        user['admin'] = users.is_current_user_admin()
        
        if user['user']:
            user['url'] = users.create_logout_url(request.get_full_path())
        else:
            user['url'] = users.create_login_url(request.get_full_path())
    
        request.ga_user = user
    